<template><div><h2 id="常见问题汇总" tabindex="-1"><a class="header-anchor" href="#常见问题汇总"><span>常见问题汇总</span></a></h2>
<h3 id="前端控制台js报错" tabindex="-1"><a class="header-anchor" href="#前端控制台js报错"><span>前端控制台JS报错？</span></a></h3>
<p>如果发现这个问题，绝大部分都是因为静态资源文件有问题引起的（比如升级步骤不正确），请先重新发布资源并<strong>清理浏览器缓存</strong>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">php artisan admin<span class="token punctuation">:</span>publish <span class="token operator">--</span>assets <span class="token operator">--</span>force</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>如果还是报错，请到此处进行反馈 <a href="https://github.com/jqhph/dcat-admin/issues" target="_blank" rel="noopener noreferrer">github.com/jqhph/dcat-admin/issues</a></p>
<h3 id="如何设置语言为简体中文" tabindex="-1"><a class="header-anchor" href="#如何设置语言为简体中文"><span>如何设置语言为简体中文？</span></a></h3>
<p>打开配置文件<code v-pre>config/app.php</code>，设置<code v-pre>locale</code>参数的值为<code v-pre>zh_CN</code>。</p>
<h3 id="laravel7时间显示为utc格式" tabindex="-1"><a class="header-anchor" href="#laravel7时间显示为utc格式"><span>Laravel7时间显示为UTC格式</span></a></h3>
<p>这个是<code v-pre>Laravel7</code>升级后带来的坑，原因请参考<a href="https://learnku.com/docs/laravel/7.x/upgrade/7445#date-serialization" target="_blank" rel="noopener noreferrer">日期序列化</a>。</p>
<p>在本项目中解决这个问题很简单，只需在<code v-pre>Model</code>中引入<code v-pre>Dcat\Admin\Traits\HasDateTimeFormatter</code>这个<code v-pre>trait</code>即可。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Models</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Traits<span class="token punctuation">\</span>HasDateTimeFormatter</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Database<span class="token punctuation">\</span>Eloquent<span class="token punctuation">\</span>Model</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">MyModel</span> <span class="token keyword">extends</span> <span class="token class-name">Model</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">     <span class="token keyword">use</span> <span class="token package">HasDateTimeFormatter</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="表单保存时报错array-to-string-conversion" tabindex="-1"><a class="header-anchor" href="#表单保存时报错array-to-string-conversion"><span>表单保存时报错<code v-pre>Array to string conversion</code></span></a></h3>
<p>出现这个问题是因为表单提交的值最后转换成了<code v-pre>array</code>类型，而<code v-pre>MySQL</code>是不支持直接存储<code v-pre>array</code>类型数据的，在<code v-pre>dcat-admin</code>中可以用以下方式对数据格式进行转换</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$form</span><span class="token operator">-></span><span class="token function">multipleSelect</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user_id'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">saving</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$v</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token comment">// 转为 , 隔开的字符串</span></span>
<span class="line"> <span class="token keyword">return</span> <span class="token function">implode</span><span class="token punctuation">(</span><span class="token string single-quoted-string">','</span><span class="token punctuation">,</span> <span class="token variable">$v</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>当然，也可以通过<code v-pre>model</code>的<strong>修改器</strong>去转化字段的值，这方面内容可以参考<code v-pre>laravel</code>文档，这里就不再赘述。</p>
<blockquote>
<p>更优雅的转化值方法，可参考 <a href="https://learnku.com/articles/44386" target="_blank" rel="noopener noreferrer">Dcat Admin 教程 - 如何优雅地更改表单值的数据类型？</a></p>
</blockquote>
<h3 id="如何从laravel-admin迁移到dcat-admin" tabindex="-1"><a class="header-anchor" href="#如何从laravel-admin迁移到dcat-admin"><span>如何从laravel-admin迁移到dcat-admin？</span></a></h3>
<p><a href="https://learnku.com/articles/44235" target="_blank" rel="noopener noreferrer">Dcat Admin 教程 - 如何从 Laravel admin 迁移到 dcat admin？</a></p>
<h3 id="重写登陆页面和登陆逻辑" tabindex="-1"><a class="header-anchor" href="#重写登陆页面和登陆逻辑"><span>重写登陆页面和登陆逻辑</span></a></h3>
<p>方式一，重写登陆控制器方法：</p>
<p>默认的登陆控制器用的是<code v-pre>App\Admin\AuthController</code>这个类，可以通过配置参数<code v-pre>admin.auth.controller</code>进行修改</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>Controllers<span class="token punctuation">\</span>AuthController</span> <span class="token keyword">as</span> BaseAuthController<span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">AuthController</span> <span class="token keyword">extends</span> <span class="token class-name">BaseAuthController</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 自定义登陆view模板</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token variable">$view</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'admin.login'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 重写登陆页面逻辑</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">getLogin</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Content</span> <span class="token variable">$content</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token operator">...</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>方式二，覆写路由：</p>
<p>在路由文件<code v-pre>app/Admin/routes.php</code>中，覆盖掉登陆页面和登陆逻辑的路由，即可实现自定义的功能</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Route</span><span class="token operator">::</span><span class="token function">group</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'prefix'</span>        <span class="token operator">=></span> <span class="token function">config</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'admin.prefix'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'namespace'</span>     <span class="token operator">=></span> <span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">controllerNamespace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'middleware'</span>    <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'web'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'admin'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Router</span> <span class="token variable">$router</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$router</span><span class="token operator">-></span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'auth/login'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'AuthController@getLogin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$router</span><span class="token operator">-></span><span class="token function">post</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'auth/login'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'AuthController@postLogin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在自定义的路由器AuthController中的<code v-pre>getLogin</code>、<code v-pre>postLogin</code>方法里分别实现自己的登陆页面和登陆逻辑。</p>
<h3 id="更新新版本后出现异常" tabindex="-1"><a class="header-anchor" href="#更新新版本后出现异常"><span>更新新版本后出现异常</span></a></h3>
<p>如果遇到更新之后,部分组件不能正常使用,那有可能是<code v-pre>dcat-admin</code>自带的静态资源有更新了,需要运行命令<code v-pre>php artisan admin:publish --force</code>来重新发布前端资源，发布之后不要忘记清理浏览器缓存.</p>
<h3 id="文件上传失败或无法访问" tabindex="-1"><a class="header-anchor" href="#文件上传失败或无法访问"><span>文件上传失败或无法访问？</span></a></h3>
<p>如果你发现无法上传文件，那么通常有几下几点原因：</p>
<ol>
<li><code v-pre>Laravel</code>文件上传配置不正确，请参考文档<a href="https://learnku.com/docs/dcat-admin/1.x/picture-file-upload/8106" target="_blank" rel="noopener noreferrer">图片/文件上传</a>。如果你不了解<code v-pre>laravel</code>文件上传功能，请阅读文档<a href="https://learnku.com/docs/laravel/7.x/filesystem/7485" target="_blank" rel="noopener noreferrer">Laravel - 文件存储</a></li>
<li>文件过大，需要调整<code v-pre>php.ini</code>的<code v-pre>upload_max_filesize</code>参数</li>
<li>文件上传目录没有写权限</li>
<li><code v-pre>php</code>没有安装或没有开启<code v-pre>fileinfo</code>扩展</li>
<li>检查<code v-pre>php.ini</code>的<code v-pre>upload_tim_dir</code>参数设置是否正常</li>
<li>检查是否升级新版本没有重新发布资源或没有清理浏览器缓存</li>
</ol>
<p>如果文件上传成功了，却无法正常访问，那么可能是<code v-pre>.env</code>配置文件中的<code v-pre>APP_URL</code>参数没有设置正确。</p>
<h3 id="关于前端资源加载问题" tabindex="-1"><a class="header-anchor" href="#关于前端资源加载问题"><span>关于前端资源加载问题</span></a></h3>
<p><code v-pre>Dcat Admin</code>是支持前端资源按需加载的，在需要用到某个组件的时候再引入前端资源即可，开发者无需担心安装组件过多影响页面加载速度。</p>
<p>只有那种需要在全局页面引入的资源，才需要在<code v-pre>app/Admin/bootstrap.php</code>或<code v-pre>ServiceProvider::boot</code>方法中引入：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'path/to/your/css'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">js</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'path/to/your/js'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="谷歌字体加载过慢" tabindex="-1"><a class="header-anchor" href="#谷歌字体加载过慢"><span>谷歌字体加载过慢？</span></a></h3>
<p>如果出现谷歌字体加载过慢的情况下，可以把谷歌字体下载到你自己的服务器，然后在<code v-pre>app/Admin/bootstrap.php</code>中加入以下代码，让系统从你自己的服务器中加载字体</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">asset</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">alias</span><span class="token punctuation">(</span></span>
<span class="line">    <span class="token string single-quoted-string">'@nunito'</span><span class="token punctuation">,</span> </span>
<span class="line">     <span class="token punctuation">[</span><span class="token string single-quoted-string">'css'</span> <span class="token operator">=></span> <span class="token function">asset</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'你的服务器字体路径/nunito.css?family=Nunito:200,200i,300,300i,400,400i,600,600i,800,800i,900,900i'</span><span class="token punctuation">)</span><span class="token punctuation">]</span></span>
<span class="line"><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你完全不想使用这两种字体，可以加入以下代码</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Admin</span><span class="token operator">::</span><span class="token function">asset</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">alias</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'@nunito'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="为何配置了角色和权限-依然提示无权访问" tabindex="-1"><a class="header-anchor" href="#为何配置了角色和权限-依然提示无权访问"><span>为何配置了角色和权限，依然提示无权访问？</span></a></h3>
<p>这个原因可能是由于权限的<code v-pre>URL</code>路径配置错误导致的，正确的包含增删改查功能的<code v-pre>URL</code>配置应该是<code v-pre>auth/users*</code>这样的，如果配置成了<code v-pre>auth/users/*</code>，那么就会提示无权访问。</p>
<blockquote>
<p>{tip} 另外标签表单填写自定义URL有两种方法：一种是选中后按<code v-pre>删除键</code>进行更改；另一种是填写后按<code v-pre>空格键</code> + <code v-pre>回车键</code>。</p>
</blockquote>
<h3 id="为何没有权限的菜单不会自动隐藏" tabindex="-1"><a class="header-anchor" href="#为何没有权限的菜单不会自动隐藏"><span>为何没有权限的菜单不会自动隐藏？</span></a></h3>
<p>权限与菜单是相互独立的，并且默认是可见的。当设置了权限之后，系统并没有办法可以判断用户是否可以访问某个菜单，所以需要给菜单绑定对应的<strong>权限</strong>或者<strong>角色</strong>，绑定之后系统就可以识别用户是否可访问这个菜单。</p>
<h3 id="项目使用https之后无法登陆" tabindex="-1"><a class="header-anchor" href="#项目使用https之后无法登陆"><span>项目使用HTTPS之后无法登陆</span></a></h3>
<p>需要把配置文件的<code v-pre>admin.https</code>参数的值设置为<code v-pre>true</code></p>
<h3 id="get-xxx-没有反应" tabindex="-1"><a class="header-anchor" href="#get-xxx-没有反应"><span>$.get(xxx) 没有反应</span></a></h3>
<p><code v-pre>Dcat Admin</code>使用的是<code v-pre>jQuery3.x</code>，<code v-pre>$.get</code>方法在<code v-pre>jQuery3.x</code>中已经被废弃，请使用<code v-pre>$.ajax</code>代替</p>
<h3 id="前后台session发生冲突" tabindex="-1"><a class="header-anchor" href="#前后台session发生冲突"><span>前后台session发生冲突</span></a></h3>
<p>从<code v-pre>2.0</code>的版本之后 <code v-pre>admin.session</code> 中间件不再默认启用，如果您的应用同时有前台和后台，则需要开启 <code v-pre>admin.session</code> 中间件，否则会造成前后台 <code v-pre>session</code> 冲突问题。</p>
<p>把配置参数 <code v-pre>admin.route.enable_session_middleware</code> 的值设置为 <code v-pre>true</code> 即可开启</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">    <span class="token string single-quoted-string">'route'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'domain'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'ADMIN_ROUTE_DOMAIN'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">        <span class="token string single-quoted-string">'prefix'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'ADMIN_ROUTE_PREFIX'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'admin'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">        <span class="token string single-quoted-string">'namespace'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'App\\Admin\\Controllers'</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">        <span class="token string single-quoted-string">'middleware'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'web'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'admin'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">        <span class="token comment">// 开启 admin.session 中间件</span></span>
<span class="line">        <span class="token string single-quoted-string">'enable_session_middleware'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="数据表字段设置-not-null-后保存表单时报错" tabindex="-1"><a class="header-anchor" href="#数据表字段设置-not-null-后保存表单时报错"><span>数据表字段设置 Not null 后保存表单时报错</span></a></h3>
<p>如果数据表字段设置为<code v-pre>not null</code>，当表单提交的数据是空时，会保存字段值为<code v-pre>null</code>到数据库，这时就会报错。我们可以通过以下方法解决这个问题</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$form</span><span class="token operator">-></span><span class="token function">text</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">saving</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token variable">$v</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// 把字段值类型强转为 string，如果是数值强转为int</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token keyword type-casting">string</span><span class="token punctuation">)</span> <span class="token variable">$v</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="图片防盗链" tabindex="-1"><a class="header-anchor" href="#图片防盗链"><span>图片防盗链</span></a></h3>
<p>图片请求默认会去掉 <code v-pre>referer</code> 字段，如果有防盗链要求，可以在配置文件(<code v-pre>config/admin.php</code>)中设置：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"> <span class="token string double-quoted-string">"disable_no_referrer_meta"</span> <span class="token operator">=></span> <span class="token constant boolean">true</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="适配-laravel-s" tabindex="-1"><a class="header-anchor" href="#适配-laravel-s"><span>适配 Laravel-S</span></a></h3>
<p>自从 Laravel-S 3.7.18 发行版开始，支持使用 DcatAdmin 。</p>
<p>1，<code v-pre>composer require hhxsv5/laravel-s</code>。</p>
<p>2，执行 <code v-pre>php artisan laravels publish</code> 发布资源。</p>
<p>3，修改 <code v-pre>config/laravels.php</code> ，添加以下服务注册和清理器：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'register_providers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line"> <span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>Dcat<span class="token punctuation">\</span>Admin<span class="token punctuation">\</span>AdminServiceProvider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line"><span class="token string single-quoted-string">'cleaners'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">  <span class="token operator">...</span></span>
<span class="line">  <span class="token class-name class-name-fully-qualified static-context">Hhxsv5<span class="token punctuation">\</span>LaravelS<span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Cleaners<span class="token punctuation">\</span>DcatAdminCleaner</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>4，执行 <code v-pre>php bin/laravels start</code> 即可使用 swoole 。</p>
<h3 id="为何不开发成前后端分离项目" tabindex="-1"><a class="header-anchor" href="#为何不开发成前后端分离项目"><span>为何不开发成前后端分离项目？</span></a></h3>
<p>最近有很多同学问我为什么不采用前后端分离技术方案，我在这个帖子里回答的非常详细，有相关疑问的同学请<a href="https://github.com/jqhph/dcat-admin/issues/27" target="_blank" rel="noopener noreferrer">点击此处查看帖子</a>，这里不再赘述。</p>
</div></template>


